package com.fleapx.spring.hook.springhooktest.beanDefinitionRegistryPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 该接口相当于具有了BeanFactoryPostProcessor接口与ImportBeanDefinitionRegistrar接口两者的能力
 */
@Component
public class BeanDefinitionRegistryPostProcessorTest implements BeanDefinitionRegistryPostProcessor {
    /**
     * 对BeanDefinition进行注册、移出操作
     * @param beanDefinitionRegistry
     * @throws BeansException
     */
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        System.out.println("BeanDefinition进行注册");
        System.out.println(beanDefinitionRegistry.getBeanDefinitionNames().toString());
    }

    /**
     * 可以获取容器中的BeanDefinition
     * @param configurableListableBeanFactory
     * @throws BeansException
     */
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        System.out.println("获取BeanDefinition进行----------");
        System.out.println(configurableListableBeanFactory.getBean("user"));
    }
}
